package com.zz.chenko.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zz.chenko.common.utils.CollectionUtil;
import com.zz.chenko.sys.dao.RoleDao;
import com.zz.chenko.sys.dao.UserDao;
import com.zz.chenko.sys.entity.Role;
import com.zz.chenko.sys.entity.UserRole;
import com.zz.chenko.sys.service.RoleService;
import com.zz.chenko.sys.service.UserRoleService;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author Zhong
 * @since 2017-05-16
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleService {

    @Autowired
    private UserDao userDao;
    @Autowired
    private UserRoleService userRoleService;

    @SuppressWarnings("unchecked")
    @Override
    public List<Role> getListByUserId(Long userId) {
        // 取得当前用户所有角色
        Map<String, Object> map = new HashMap<>();
        map.put("USER_ID", userId);
        List<UserRole> userRoleList = userRoleService.selectByMap(map);
        List<Long> roleIds = CollectionUtil.extractToList(userRoleList, "roleId");
        List<Role> roleList = this.selectBatchIds(roleIds);
        return roleList;
    }

}
